#include "bs_pull_streamer.h"
#include "video_generater.h"

#include <yaml-cpp/yaml.h>

/*
    使用bs_push_streamer进行推流的例子
*/

int main(int argc, char **argv)
{
    // 读取yaml配置文件
    /* -----------------------------------------------------*/
    if (argc < 2)
    {
        fmt::print("usage: rtsp_pusher_demo [config]\n");
        return -1;
    }

    std::string config_path = argv[1];

    YAML::Node yaml_cfg;
    try
    {
        yaml_cfg = YAML::LoadFile(config_path);
    }
    catch (YAML::BadFile &e)
    {
        fmt::print("read yaml error!\n");
        return -1;
    }

    std::string name = yaml_cfg["name"].as<std::string>();
    std::string decoder = yaml_cfg["decoder"].as<std::string>();

    fmt::print("read yaml OK!\n");
    /* -----------------------------------------------------*/

    // 调用setup进行初始化并使用stream推流
    /* -----------------------------------------------------*/
    BsPullStreamer mBsPullStreamer;

    if (!mBsPullStreamer.setup(name, decoder))
    {
        std::cout << "mBsPullStreamer.start fail!\n";
        return -1;
    }
    std::cout << "mBsPullStreamer.start success!\n";

    auto start_time = std::chrono::steady_clock::now();
    auto cnt_time = std::chrono::steady_clock::now();

    // 拉流
    while (mBsPullStreamer.is_running())
    {
        std::this_thread::sleep_for(std::chrono::milliseconds(1000));
    }

    std::cout << "mBsPullStreamer.stop success!\n";
    /* -----------------------------------------------------*/



    return 0;
}
